﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Chess
{
	class Pawn : Piece
	{
		private bool HasMoved;

		public Pawn(Team _color, Point _position, ref Piece[,] _board)
			: base(_color, _position, ref _board)
		{
			HasMoved = false;
		}

		public override void Refresh()
		{
			ValidMoves.Clear();

			// Move straight
			if (Board[Position.X + Direction, Position.Y] == null || Board[Position.X + Direction, Position.Y].Color != Color)
			{
				ValidMoves.Add(new Point(Position.X + Direction, Position.Y));
				if (!HasMoved && Board[Position.X + 2 * Direction, Position.Y] == null) ValidMoves.Add(new Point(Position.X + 2 * Direction, Position.Y));
			}
			
			ValidAttacks.Clear();

			// Attack
			if (Board[Position.X + Direction, Position.Y + 1] != null && Board[Position.X + Direction, Position.Y + 1].Color != Color)
				ValidAttacks.Add(new Point(Position.X + Direction, Position.Y + 1));
			if (Board[Position.X + Direction, Position.Y - 1] != null && Board[Position.X + Direction, Position.Y - 1].Color != Color)
				ValidAttacks.Add(new Point(Position.X + Direction, Position.Y - 1));
		}

		// Update Position and Board
		public override void Move(Point _position)
		{
			HasMoved = true;

			// Check if taking piece.
			//if(Board[_position.X, _position.Y] != null); // Dispose of piece

			// TODO: Check if reaching the end of the board. KING!!!

			Board[_position.X, _position.Y] = this;
			Position = _position;
		}
	}
}
